//
//  LiveViewController.m
//  逗她盒子
//
//  Created by Qiaofeng on 15/6/9.
//  Copyright (c) 2015年 Qiaofeng. All rights reserved.
//

#import "LiveViewController.h"
#import <AFNetworking.h>
#import "LiveModel.h"
#import "LiveTableViewCell.h"
@interface LiveViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)NSMutableArray *array;
@property (nonatomic, retain)UITableView *table;
@end

@implementation LiveViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self =  [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
//        http://api.maxjia.com/api/video/list/?offset=0&limit=30&phone_num=00000000000&pkey=randpkey&os_type=iOS&os_version=8.3&_time=1434366724&version=1.0.0
        self.array = [NSMutableArray array];
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        NSString *url = [NSString stringWithFormat:@"http://api.maxjia.com/api/video/list/?"];
        [manager.requestSerializer setValue:@"http://api.maxjia.com/" forHTTPHeaderField:@"Referer"];
        NSDictionary *parameters = @{@"offset":@"0", @"limit":@"30", @"phone_num":@"00000000000", @"pkey":@"randpkey", @"os_type":@"iOS",@"os_version":@"8.3",@"time":@"1433927795", @"version":@"1.0.0"};
        [manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSDictionary *BigDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSDictionary *resultDic = [BigDic objectForKey:@"result"];
            NSDictionary *playersDic = [resultDic objectForKey:@"video_list_by_time"];
            for (NSDictionary *players in playersDic) {
                LiveModel *model = [[LiveModel alloc]init];
                [model setValuesForKeysWithDictionary:players];
                [self.array addObject:model];
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            
        }];

        


    }
    return self;
}
- (void)createtableView
{
    self.table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LiveModel *model = [[LiveModel alloc]init];
    model = [self.array objectAtIndex:indexPath.row];
    static NSString *cellIdentify = @"cell";
    LiveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[LiveTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentify];
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 130;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createtableView];
    

}




@end
